package com.xbongbong.paas.help.symbol;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.StringUtil;

import java.util.Objects;

/**
 * 所属部门
 * @author 吴峰
 * @date 2021/01/07 15:02
 */
public class DepartmentIdSymbolHandle extends TextSymbolHandle {

    @Override
    public boolean equals(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {
        long tempLong =  source.getDepartmentId();
        if(tempLong <= Integer.MAX_VALUE && tempLong >= Integer.MIN_VALUE){
            return Objects.equals(target, (int) tempLong);
        }else{
            return Objects.equals(target, source.getDepartmentId());
        }
    }

    @Override
    public boolean noEquals(Object target, PaasFormDataEntity source,  FieldAttrEntity fieldAttrEntity) throws XbbException {
        return !this.equals(target, source, fieldAttrEntity);
    }

    @Override
    public boolean empty(PaasFormDataEntity source,  FieldAttrEntity fieldAttrEntity) throws XbbException {
        if (Objects.isNull(source)) {
            return true;
        }
        Long data = source.getDepartmentId();
        return Objects.isNull(data) || StringUtil.isEmpty(data.toString()) || Objects.equals(0L, data);
    }

    @Override
    public boolean noEmpty(PaasFormDataEntity source,  FieldAttrEntity fieldAttrEntity) throws XbbException {
        if (Objects.isNull(source)) {
            return false;
        }
        Long data = source.getDepartmentId();
        return Objects.nonNull(data) && StringUtil.isNotEmpty(data.toString()) && !Objects.equals(0L, data);
    }
}
